﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataAccess;
using Model.EntityModel;

namespace Project
{
    /// <summary>
    /// Interaction logic for PrintRemissionOfCase.xaml
    /// </summary>
    public partial class PrintRemissionOfCase : UserControl
    {
        private long ComplaintId;
        private RemissionOfCase RemissionOfCurrentCase;

        public PrintRemissionOfCase(long complaintId)
        {
            ComplaintId = complaintId;
            InitializeComponent();
            RemissionOfCurrentCase = ComplaintDataAccess.GetRemissionOfCase(ComplaintId);
            SetRemissionOfCase();
            var complaint = ComplaintDataAccess.GetComplaintById(complaintId);
            Actor complainant = new Actor();
            Actor aggressor = new Actor();
            foreach (var actor in complaint.Actor)
            {
                if (actor.Type == "Denunciante")
                    complainant = actor;
                if (actor.Type == "Agresor")
                    aggressor = actor;
            }
            lblComplainantName.Content = complainant.Person.Name + " " + complainant.Person.PaternalName + " " +
                                         complainant.Person.MaternalName;
            lblComplainantCi.Content = complainant.Person.CiPassport;

            lblAggressorName.Content = aggressor.Person.Name + " " + aggressor.Person.PaternalName + " " +
                                       aggressor.Person.MaternalName;
            lblAggressorCi.Content = aggressor.Person.CiPassport;
            var employees = ComplaintDataAccess.GetAllEmployeeOfComplaintFromComp(ComplaintId);
            foreach (var employeeOfComplaint in employees)
            {
                if (employeeOfComplaint.Responsability == "Asignada")
                    lblAsignedName.Content = employeeOfComplaint.Employee.Name + " " +
                                             employeeOfComplaint.Employee.PaternalName + " " +
                                             employeeOfComplaint.Employee.MaternalName;
            }
        }

        private void SetRemissionOfCase()
        {
            lblCaseNumber.Content = RemissionOfCurrentCase.ComplaintId;
            lblCaseNum.Content = RemissionOfCurrentCase.ComplaintId;
            lblRemissionDate.Content = RemissionOfCurrentCase.RemisionDate.ToShortDateString();
            tbRemitedPeople.Text = RemissionOfCurrentCase.RemmitedPersons;
            tbRemitedPeople.IsReadOnly = true;
            tbMrOrMs.Content = RemissionOfCurrentCase.IntendedForMrOrMrs;
            tbInstitution.Content = RemissionOfCurrentCase.Institution;
            tbFojasNumber.Content = RemissionOfCurrentCase.FoliosNumber.ToString();
            tbImpedimentDays.Content = RemissionOfCurrentCase.ImpedimentDays.ToString();
            lblMrOrMs.Content = RemissionOfCurrentCase.IntendedForMrOrMrs;
        }
    }
}
